import { _decorator, Component, Node } from 'cc';
const { ccclass, property } = _decorator;

// 为 Array 添加扩展方法
declare global {
    interface Array<T> {
        removeAll(element: T): void;
        findFirst(predicate: (value: T) => boolean): T | undefined;
        remove(element:T):void;
    }
}

Array.prototype.removeAll = function<T>(this: T[], element: T) {
    let index: number;
    while ((index = this.indexOf(element)) > -1) {
        this.splice(index, 1);
    }
};

Array.prototype.findFirst = function<T>(this: T[], predicate: (value: T) => boolean): T | undefined {
    for (let i = 0; i < this.length; i++) {
        if (predicate(this[i])) {
            return this[i];
        }
    }
    return undefined;
};

Array.prototype.remove = function<T>(this: T[], element: T) {
    const index = this.indexOf(element);
    if (index > -1) {
        this.splice(index, 1);
    }
};


